# $Id$
# Maintainer: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>

pkgname=go-tools
epoch=2
pkgver=1.9+2247+5d2fd3cc
pkgrel=1
pkgdesc='Developer tools for the Go programming language'
arch=(i686 x86_64)
url='http://golang.org/'
license=(BSD)
depends=(glibc)
makedepends=(git go-pie)
_commit=5d2fd3ccab986d52112bf301d47a819783339d0e
_net_commit=ab5485076ff3407ad2d02db054635913f017b0ed
source=(git+https://go.googlesource.com/tools#commit=$_commit
        git+https://github.com/golang/net#commit=$_net_commit)
md5sums=('SKIP'
         'SKIP')

_tools=(benchcmp callgraph cover digraph eg fiximports godex godoc goimports
        gomvpkg gorename gotype goyacc guru heapview html2article present
        ssadump stringer)

pkgver() {
  local _gover=1.9
  cd tools
  printf "%s+%s+%s" $_gover "$(git rev-list --count HEAD)" \
    "$(git rev-parse --short HEAD)"
}

prepare() {
  mkdir -p gopath/src/golang.org/x build
  cp -r tools net gopath/src/golang.org/x/
}

build() {
  export GOPATH="$srcdir/gopath"

  cd build
  for tool in ${_tools[@]}; do
    go build -v -a golang.org/x/tools/cmd/$tool
  done
}

check() {
  export GOPATH="$srcdir/gopath"

  for tool in ${_tools[@]}; do
    go test golang.org/x/tools/cmd/$tool
  done
}

package() {
  for tool in ${_tools[@]}; do
    install -Dm755 build/$tool "$pkgdir/usr/bin/$tool"
  done

  install -Dm644 tools/LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
